package com.ziq.baselib.test.livedata

import android.annotation.SuppressLint
import android.os.Bundle
import com.ziq.base.base.BaseActivity
import com.ziq.base.extension.binding
import com.ziq.base.extension.click
import com.ziq.base.utils.LogUtil
import com.ziq.baselib.databinding.ActivityHiltBinding
import com.ziq.baselib.databinding.ActivityLiveDataBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class LiveDataActivity: BaseActivity() {

    private val binding : ActivityLiveDataBinding by binding()

    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.root

        LiveDataManager.list.observe(this){
            LogUtil.i("LiveDataActivity", "liveData = ${it}")
        }
        binding.btn.click {
            updateData()
        }
    }

    fun updateData(){
        var list = LiveDataManager.list.value
        if(list == null){
            list = mutableListOf()
        }
        list.add(list.size)
        LiveDataManager.list.value = list
    }

    override fun onResume() {
        super.onResume()
        LogUtil.i("LiveDataActivity", "onResume")
    }

    override fun onStop() {
        super.onStop()
        LogUtil.i("LiveDataActivity", "onStop")
        updateData()
    }
}